<template>
  <div class="app-container">
    <div
      v-show="
        !modifyInfo.visible &&
        !detailInfo.visible &&
        !purchAppDetailinfo.visible &&
        !detailListInfo.visible
      "
    >
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <new-page-filter
          v-model:query="filterInfo.query.queryMap"
          :query-more-json="true"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :clear-type="clearType"
          :slipSelectRequest="slipSelectRequest"
        >
        </new-page-filter>
        <el-button @click="detailListInfo.visible = true">明细页</el-button>
      </div>
      <div class="filter-wrapper">
        <new-page-filter :filter-btn="filterInfo.btnList">
          <!-- <template v-slot:filter-revoke>
            <el-button
              :disabled="!canRevoke"
              @click="handelMethodRequest(undefined, 'revoke')"
              >撤回
            </el-button>
          </template>
          <template v-slot:filter-cancelAudit>
            <el-button
              :disabled="!canCancelAudit"
              @click="handelMethodRequest(undefined, 'cancelAudit')"
              >销审
            </el-button>
          </template> -->
          <template v-slot:filter-check>
            <el-button
              :disabled="!canCheck"
              @click="
                handelMethodRequest(
                  undefined,
                  $store.state.permission.systemConfig
                    .allow_asset_purch_order_approval == 2
                    ? 'flowApproved'
                    : 'check'
                )
              "
              >批准
            </el-button>
          </template>
          <!-- <template v-slot:filter-break>
            <el-button
              :disabled="!canBreak"
              @click="handelMethodRequest(undefined, 'break')"
              >中止
            </el-button>
          </template>
          <template v-slot:filter-submit>
            <el-button
              :disabled="!canSubmit"
              @click="
                handelMethodRequest(
                  undefined,
                  $store.state.permission.systemConfig
                    .allow_asset_purch_order_approval == 2
                    ? 'flowSubmit'
                    : 'submit'
                )
              "
              >提交
            </el-button>
          </template>
          <template v-slot:filter-print>
            <el-button :disabled="!canPrint" @click="print()">打印</el-button>
          </template>
          <template v-slot:filter-excel>
            <el-button :disabled="!canExcel" @click="exportExcel()"
              >导出excel</el-button
            >
          </template>
          <template v-slot:filter-addContract>
            <el-button @click="addContract">合同导入</el-button>
          </template> -->
        </new-page-filter>
        <div class="display-flex">
          <el-button @click="preferenceInfo.visible = true">偏好设置</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <table-container
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :handle="tableInfo.handle"
        :row-class-name="tableRowClassName"
        @pageInfo="pageInfo"
        @handleEvent="handleEvent"
      >
        <template v-slot:col-orderNo="scope">
          <span
            v-if="$permission('assetPurchOrder:detail')"
            class="slip-edit"
            @click="showDetail(scope.row)"
            >{{ scope.row.orderNo || '-' }}</span
          >
          <span v-else>{{ scope.row.orderNo || '-' }}</span>
        </template>
      </table-container>
    </div>
    <!-- 新增或修改 -->
    <asset-purch-order-modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :orderId="modifyInfo.orderId"
      :contract-id="modifyInfo.contractId"
      :contract-no="modifyInfo.contractNo"
      :table-data="modifyInfo.tableData"
      :tableKey="modifyInfo.tableKey"
      @returnModify="returnModify"
    />
    <asset-purch-order-detail
      v-if="detailInfo.visible"
      v-model:visible="detailInfo.visible"
      :orderId="detailInfo.orderId"
      @returnBack="getList"
    />
    <set-preference
      v-if="preferenceInfo.visible"
      v-model:visible="preferenceInfo.visible"
      :search-list="filterInfo.searchList"
      :field-list="tableInfo.fieldList"
      :customize-user-v-o="filterInfo.query.customizeUserVO"
      :group-level-show="false"
      @callback="setPreferenceCallback"
    />
    <advanced-search
      v-if="advancedSearchInfo.visible"
      v-model:visible="advancedSearchInfo.visible"
      v-model:form-data="advancedSearchInfo.data"
      :field-list="tableInfo.fieldList"
      @callback="advancedSearchCallback"
    />
    <detailList
      v-if="detailListInfo.visible"
      v-model:visible="detailListInfo.visible"
      @callback="getList"
    ></detailList>
    <!--合同选择-->
    <SelectContractStore
      v-if="addContractDialog.visible"
      v-model:visible="addContractDialog.visible"
      :query="addContractDialog.query"
      :title="'选择合同'"
      @callback="addContractBack"
    />
    <page-dialog
      v-show="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <div class="asset-msg">
        <div class="asset-msg-label">
          <i class="el-icon-warning"></i>{{ dialogInfo.msg }}：
        </div>
        <el-radio-group v-model="dialogInfo.flag">
          <el-radio :label="true">当前页数据</el-radio>
          <el-radio :label="false">全部页数据</el-radio>
        </el-radio-group>
      </div>
    </page-dialog>
  </div>
</template>

<script setup name="drugPurch">
import {
  getAssetPurchOrderCustomizeListPage,
  methodAssetPurchOrder,
  removeAssetPurchOrder,
  printAssetPurchOrderList,
  exportAssetPurchOrderList,
} from '@/api/drug.js'
import { getSupplierAll } from '@/api/core'
import { getCustomizeSetting } from '@/api/customize'
import { fatchTemplateByCode } from '@/api/base'
const detailList = defineAsyncComponent(() => import('./detailList'))
const AssetPurchOrderModify = defineAsyncComponent(() => import('./modify'))
const AssetPurchOrderDetail = defineAsyncComponent(() => import('./detail'))

const { proxy } = getCurrentInstance()

const dialogInfo = ref({
  visible: false,
  title: '提示',
  btLoading: false,
  type: '',
  msg: '',
  width: '400px',
  flag: true,
  btList: [
    {
      label: '关闭',
      event: handleClose,
      show: true,
    },
    {
      label: '打印',
      type: 'primary',
      event: checkConfirm,
      show: true,
    },
  ],
})
const listTypeInfo = ref({
  supplierList: [],
  typeList: [],
})
const modifyTaleKey = ref(
  'assetPurchOrderDetailModify-com.slip.spd.entity.vo.purch.PurchOrderDetailVO'
)
const filterInfo = ref({
  query: {
    sortString: '',
    customizeUserVO: {},
    queryMap: {
      deptAuth: {
        asTbName: 'purch_order',
        columnName: 'dept_id',
        queryType: 'IN',
        queryCategory: 'AND',
        value: 'deptAuth',
      },
      purchProductType: {
        asTbName: 'purch_order',
        columnName: 'purch_product_type',
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: '2',
      },
    },
  },
  searchList: [],
  btnList: [
    // {
    //   type: 'button',
    //   label: '新增',
    //   event: create,
    //   show: proxy.$permission('assetPurchOrder:add'),
    // },
    // {
    //   type: 'slot',
    //   value: 'break',
    //   show: proxy.$permission('assetPurchOrder:break'),
    // },
    // {
    //   type: 'slot',
    //   value: 'merge',
    //   show: proxy.$permission('assetPurchOrder:merge'),
    // },
    {
      type: 'slot',
      value: 'check',
      show: proxy.$permission('assetPurchOrder:check'),
    },
    // {
    //   type: 'slot',
    //   value: 'submit',
    //   show: proxy.$permission('assetPurchOrder:submit'),
    // },
    // {
    //   type: 'slot',
    //   value: 'revoke',
    //   show: proxy.$permission('assetPurchOrder:revoke'),
    // },
    // {
    //   type: 'slot',
    //   value: 'cancelAudit',
    //   show: proxy.$permission('assetPurchOrder:cancelAudit'),
    // },
    // {
    //   type: 'slot',
    //   value: 'addContract',
    //   show: proxy.$permission('assetPurchOrder:addContract'),
    // },
    // {
    //   type: 'slot',
    //   value: 'print',
    //   show: proxy.$permission('assetPurchOrder:printList'),
    // },
    // {
    //   type: 'slot',
    //   value: 'excel',
    //   show: proxy.$permission('assetPurchOrder:excel'),
    // },
  ],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '高级查询', event: advancedSearchShow },
    { type: 'button', label: '重置', event: clearSearch },
  ],
})
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  selections: [],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      // {
      //   label: '修改',
      //   event: update,
      //   show: proxy.$permission('assetPurchOrder:update'),
      //   ifRender: function (row) {
      //     return row.status === 1 || row.status === 5
      //   },
      // },
      // {
      //   label: '提交',
      //   event: (row) =>
      //     handelMethodRequest(
      //       row,
      //       proxy.$store.state.permission.systemConfig
      //         .allow_asset_purch_order_approval == 2
      //         ? 'flowSubmit'
      //         : 'submit'
      //     ),
      //   show: proxy.$permission('assetPurchOrder:submit'),
      //   ifRender: function (row) {
      //     return row.status === 1 || row.status === 5
      //   },
      // },
      // {
      //   label: '中止',
      //   event: (row) => handelMethodRequest(row, 'stop'),
      //   show: proxy.$permission('assetPurchOrder:stop'),
      //   ifRender: ifRenderStop,
      // },
      {
        label: '采购',
        event: (row) => handelMethodRequest(row, 'doPurch'),
        show: proxy.$permission('assetPurchOrder:doPurch'),
        ifRender: function (row) {
          return row.status === 3
        },
      },
      // {
      //   label: '撤回',
      //   event: (row) => handelMethodRequest(row, 'revoke'),
      //   show: proxy.$permission('assetPurchOrder:revoke'),
      //   ifRender: ifRenderRevoke,
      // },
      // {
      //   label: '销审',
      //   event: (row) => handelMethodRequest(row, 'cancelAudit'),
      //   show: proxy.$permission('assetPurchOrder:cancelAudit'),
      //   ifRender: ifRenderCancelAudit,
      // },
      {
        label: '批准',
        event: (row) =>
          handelMethodRequest(
            row,
            proxy.$store.state.permission.systemConfig
              .allow_asset_purch_order_approval == 2
              ? 'flowApproved'
              : 'check'
          ),
        show: proxy.$permission('assetPurchOrder:check'),
        ifRender: function (row) {
          return row.status === 2
        },
      },
      // {
      //   label: '拒绝',
      //   event: (row) =>
      //     handelMethodRequest(
      //       row,
      //       proxy.$store.state.permission.systemConfig
      //         .allow_asset_purch_order_approval == 2
      //         ? 'flowRefuse'
      //         : 'refuse'
      //     ),
      //   show: proxy.$permission('assetPurchOrder:refuse'),
      //   ifRender: function (row) {
      //     return row.status === 2
      //   },
      // },
      // {
      //   label: '驳回',
      //   event: (row) =>
      //     handelMethodRequest(
      //       row,
      //       proxy.$store.state.permission.systemConfig
      //         .allow_asset_purch_order_approval == 2
      //         ? 'flowReject'
      //         : 'reject'
      //     ),
      //   show: proxy.$permission('assetPurchOrder:reject'),
      //   ifRender: function (row) {
      //     return row.status === 2
      //   },
      // },
      // {
      //   label: '删除',
      //   event: remove,
      //   show: proxy.$permission('assetPurchOrder:delete'),
      //   ifRender: function (row) {
      //     return row.status === 1 || row.status === 5
      //   },
      // },
    ],
  },
})
const addContractDialog = ref({
  query: {
    contractType: 1,
    statusMult: '4',
    sourceType: 3,
  },
  visible: false,
})
//明细相关
const detailInfo = ref({
  visible: false,
  orderId: '',
})
const purchAppDetailinfo = ref({
  visible: false,
  title: '申购单明细',
  data: {},
})
//新增或更新相关
const modifyInfo = ref({
  visible: false,
  title: '',
  orderId: '',
  tableKey: '',
  contractId: '',
  contractNo: '',
  tableData: [],
})
const licencesSystemConfig = ref('')
const page = ref({})
const groupFlag = ref(undefined)
const lastReceiveTime = ref(undefined)
const purchTime = ref(undefined)
const advancedSearchInfo = ref({
  visible: false,
  data: {},
})
const detailListInfo = ref({
  visible: false,
})
const preferenceInfo = ref({
  visible: false,
})
const clearType = ref(true)
const slipSelectRequest = ref(true)

const canPrint = computed(() => {
  return !groupFlag.value
})
const canExcel = computed(() => {
  return !groupFlag.value
})
const canSubmit = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter((item) => item.status !== 1).length
  )
})
const canCheck = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter((item) => item.status !== 2).length
  )
})
const canRevoke = computed(() => {
  return (
    tableInfo.value.selections.filter(
      (item) =>
        item.status === 2 ||
        (item.status === 3 &&
          proxy.$store.state.permission.systemConfig
            .allow_purch_order_approval != 1 &&
          proxy.$store.state.permission.systemConfig
            .allow_purch_order_approval != 2)
    ).length !== 0 &&
    tableInfo.value.selections.filter(
      (item) => item.status !== 2 && item.status !== 3
    ).length === 0
  )
})
const canCancelAudit = computed(() => {
  return (
    tableInfo.value.selections.filter(
      (item) =>
        item.status === 3 &&
        proxy.$store.state.permission.systemConfig
          .allow_asset_purch_order_approval !== 0
    ).length !== 0 &&
    tableInfo.value.selections.filter((item) => item.status !== 3).length === 0
  )
})

const canBreak = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter(
      (item) => item.status !== 3 && item.status !== 13 && item.status !== 14
    ).length
  )
})

watch(
  () => filterInfo.value.query.lastReceiveTimeGreater,
  (val) => {
    if (!val) {
      lastReceiveTime.value = null
    }
  }
)
watch(
  () => filterInfo.value.query.purchTimeGreater,
  (val) => {
    if (!val) {
      purchTime.value = null
    }
  }
)

onMounted(() => {
  let list = proxy.$store.state.permission.dict['purch_order_status']
  if (list != undefined && list != null && list.length > 0) {
    listTypeInfo.value.typeList = list.map((item) => {
      return {
        value: item.code,
        key: item.name,
      }
    })
  }
})

setData()
function setData() {
  let obj = {
    statusValue: {
      label: '状态',
      value: 'statusValue',
      asValue: 'status',
      componentType: 'select-model',
      code: 'asset_purch_order_status',
      show: false,
      hidden: true,
    },
  }
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  filterInfo.value.searchList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...proxy.$fn.deepClone(obj),
  })
  getCustomize()
}
function pageInfo(obj) {
  page.value = obj
}
function setPreferenceCallback(obj) {
  updateUserCustomize(obj.customizeUserVO).then((res) => {
    if (res && res.success) {
      getCustomize(!slipSelectRequest.value)
    }
  })
}
function tableRowClassName({ row }) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  }
  return ''
}
function ifRenderStop(row) {
  return (
    (row.status === 3 &&
      proxy.$store.state.permission.systemConfig
        .allow_asset_purch_order_approval !== 0) ||
    row.status === 13 ||
    row.status === 14
  )
}
function ifRenderRevoke(row) {
  return (
    row.status === 2 ||
    (row.status === 3 &&
      proxy.$store.state.permission.systemConfig
        .allow_asset_purch_order_approval != 1)
  )
}
function ifRenderCancelAudit(row) {
  return (
    row.status === 3 &&
    proxy.$store.state.permission.systemConfig
      .allow_asset_purch_order_approval != 0
  )
}
function lastReceiveTimeChange(val) {
  if (val && val.length) {
    filterInfo.value.query.queryMap.lastReceiveTime.value = `${val[0]},${val[1]}`
  } else {
    filterInfo.value.query.queryMap.lastReceiveTime.value = ''
  }
}
function addContract() {
  addContractDialog.value.visible = true
}
function addContractBack(obj) {
  proxy.$nextTick(() => {
    if (obj && obj.id) {
      modifyInfo.value.contractId = obj.id
      modifyInfo.value.contractNo = obj.orderNo
      modifyInfo.value.tableData = []
      modifyInfo.value.orderId = ''
      modifyInfo.value.visible = true
      modifyInfo.value.tableKey = modifyTaleKey.value
      modifyInfo.value.title = '根据合同导入'
    }
  })
}
function purchTimeChange(val) {
  if (val && val.length) {
    filterInfo.value.query.queryMap.purchTime.value = `${val[0]},${val[1]}`
  } else {
    filterInfo.value.query.queryMap.purchTime.value = ''
  }
}
function initSupplierSelect() {
  const params = {}
  getSupplierAll(params).then((resp) => {
    if (resp && resp.success) {
      listTypeInfo.value.supplierList = resp.data.map((item) => {
        return {
          key: item.supplierName,
          value: item.supplierId,
        }
      })
    }
  })
}
function returnModify() {
  if (modifyInfo.value.orderId) {
    getList()
  } else {
    search()
  }
}
// 创建
function create() {
  modifyInfo.value.visible = true
  modifyInfo.value.title = '新增采购单'
  modifyInfo.value.orderId = ''
  modifyInfo.value.contractNo = ''
  modifyInfo.value.contractId = ''
  modifyInfo.value.tableData = []
  modifyInfo.value.tableKey = modifyTaleKey.value
}
// 编辑
function update(data) {
  sessionStorage.setItem('storeRowId', data.id)
  modifyInfo.value.visible = true
  modifyInfo.value.title = '修改采购单'
  modifyInfo.value.orderId = data.id
  modifyInfo.value.contractNo = ''
  modifyInfo.value.contractId = ''
  modifyInfo.value.tableData = []
  modifyInfo.value.tableKey = modifyTaleKey.value
}
// 获取列表
async function getList() {
  tableInfo.value.refresh = Math.random()
}
//删除
function remove(row) {
  const data = []
  data.push(row.id)
  removeAssetPurchOrder([row.id]).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.value.selections = [...data]
      break
  }
}
//展示明细
function showDetail(row) {
  sessionStorage.setItem('storeRowId', row.id)
  detailInfo.value.orderId = row.id
  detailInfo.value.visible = true
}
function showPurchAppDetail(row) {
  let obj = {}
  obj = JSON.parse(JSON.stringify(row))
  obj.id = row.applicationId
  let purchType = row.purchType
  if (purchType === 0) {
    purchAppDetailinfo.value.visible = true
    purchAppDetailinfo.value.data = { ...obj }
  }
}
async function advancedSearchCallback(obj) {
  filterInfo.value.query.queryMap = {}
  let arr = [
    {
      asTbName: 'purch_order',
      columnName: 'dept_id',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'deptAuth',
    },
    {
      fieldName: 'purchProductType',
      asTbName: 'purch_order',
      columnName: 'purch_product_type',
      queryType: 'EQUALS',
      queryCategory: 'AND',
      value: '3',
    },
  ]
  filterInfo.value.query.queryDtoList = [...obj.queryDtoList, ...arr]
  advancedSearchInfo.value.data = obj.data
  await getList()
  clearType.value = !clearType.value
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
}
function handelMethodRequest(row = undefined, method) {
  const ids = getIds(row)

  if (method === 'flowSubmit') {
    let data = {
      flowTaskCommentDto: { approvalType: 'submit' },
      processDefinitionKey: 'assetPurchOrderApply',
      orderId: row.id,
    }
    methodAssetPurchOrder(data, method).then((resp) => {
      if (resp && resp.success) {
        getCustomize()
      }
    })
  } else if (method === 'reject' || method === 'flowReject') {
    proxy
      .$prompt('请输入驳回理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: proxy.$fn.maxString200,
        inputErrorMessage: '驳回理由不能超过200字符',
      })
      .then(({ value }) => {
        const data = {
          id: row.id,
          orderId: row.id,
          checkOpt: value,
        }
        methodAssetPurchOrder(data, method).then((resp) => {
          if (resp && resp.success) {
            getList()
          }
        })
      })
  } else if (method === 'refuse' || method === 'flowRefuse') {
    proxy
      .$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: proxy.$fn.maxString200,
        inputErrorMessage: '拒绝理由不能超过200字符',
      })
      .then(({ value }) => {
        const data = {
          id: row.id,
          orderId: row.id,
          checkOpt: value,
        }
        methodAssetPurchOrder(data, method).then((resp) => {
          if (resp && resp.success) {
            getCustomize()
          }
        })
      })
  } else if (method === 'stop') {
    proxy
      .$prompt('请输入中止原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: proxy.$fn.isNotEmptyString,
        inputErrorMessage: '请输入中止原因并不超过200字符',
      })
      .then(({ value }) => {
        const data = {
          ids: ids,
          stopReason: value,
        }
        methodAssetPurchOrder(data, method).then((resp) => {
          if (resp && resp.success) {
            getCustomize()
          }
        })
      })
  } else if (method === 'flowApproved') {
    methodAssetPurchOrder({ orderIds: ids }, method).then((resp) => {
      if (resp.success) {
        tableInfo.value.refresh = Math.random()
      }
    })
  } else {
    methodAssetPurchOrder(ids, method).then((resp) => {
      if (resp.success) {
        tableInfo.value.refresh = Math.random()
      }
    })
  }
}
function getIds(row = undefined) {
  let ids = []
  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((row) => row.id)
  }
  return ids
}
function handleClose() {
  dialogInfo.value.visible = false
}
function checkConfirm() {
  if (dialogInfo.value.type === 'excel') {
    exportExcelList()
  } else if (dialogInfo.value.type === 'print') {
    printList()
  }
  dialogInfo.value.visible = false
  dialogInfo.value.msg = ''
}
function exportExcel() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'excel'
  dialogInfo.value.msg = '请选择数据导出范围'
  dialogInfo.value.btList[1].label = '导出'
  dialogInfo.value.flag = true
}
function exportExcelList() {
  let params = {
    ...filterInfo.value.query,
    ...page.value,
    page: dialogInfo.value.flag,
  }
  exportAssetPurchOrderList(params).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
async function print() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'print'
  dialogInfo.value.msg = '请选择当数据打印范围'
  dialogInfo.value.btList[1].label = '打印'
  dialogInfo.value.flag = true
}
//打印
function printList() {
  fatchTemplateByCode({
    resourceCode: 'assetPurchOrder:printList',
    isDefault: 1,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPrintData(temp, dialogInfo.value.flag)
    }
  })
}
function getPrintData(temp, flag) {
  let query = {
    customizeDto: filterInfo.value.query,
  }
  let params = {
    ...query,
    ...page.value,
    page: flag,
  }
  printAssetPurchOrderList(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData)
    }
  })
}
// 搜索
function search() {
  // 重置分页
  advancedSearchInfo.value.data = {}
  filterInfo.value.query.queryDtoList = []
  tableInfo.value.initCurpage = Math.random()
  tableInfo.value.refresh = Math.random()
}
function getCustomize(_slipSelectRequest = true) {
  let param = {
    tableKey: 'drugPurchOrderList-com.slip.spd.entity.vo.drug.DrugPurchOrderVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.value.searchList,
        data.detail
      )
      filterInfo.value.query.queryMap = {
        ...searchInfo.queryMap,
        ...filterInfo.value.query.queryMap,
      }
      filterInfo.value.searchList = searchInfo.searchList
      filterInfo.value.searchList.forEach((item) => {
        item.event = search
      })
      filterInfo.value.copyQueryMap = proxy.$fn.deepClone(
        filterInfo.value.query.queryMap
      )
      slipSelectRequest.value = _slipSelectRequest
      tableInfo.value.api = getAssetPurchOrderCustomizeListPage
      getList()
    }
  })
}
function advancedSearchShow() {
  advancedSearchInfo.value.visible = true
}
function clearSearch() {
  clearType.value = !clearType.value
  advancedSearchInfo.value.data = {}
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
  search()
}
</script>

<style scoped lang="scss">
:deep(.el-table) {
  .nearly-row {
    background: #fceacb;
  }
  .expire-row {
    background: #f5e4e4;
  }
}
</style>
